/*
 * Alloy Analyzer
 * Copyright (c) 2002 Massachusetts Institute of Technology
 *
 * The Alloy Analyzer is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * The Alloy Analyzer is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with the Alloy Analyzer; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package alloy.gui;

import javax.swing.tree.DefaultMutableTreeNode;

import alloy.ast.LeafExpr;

class AlloyGUITreeNode extends DefaultMutableTreeNode {
    private String name;
    private int nodeType;
    
    // added by vsy to reduce string-based operations
    /**
     * For a signature, this contains its sigExpr
     * For an atom, it contains its type's sigExpr
     * For a field/skolem, it contains its VarExpr
     * For a tuple, it contains the VarExpr of the field/skolem it instantiates     
     * For everything else (?), it is null
     */
    private LeafExpr leafExpr;
    /**
     * If node is an atom, contains the alloy.api.Atom it represents.
     * Otherwise this variable is null
     */
    private alloy.api.Atom atom;
    

    //indicates if we have already constructed the children of this node.
    boolean alreadyExpanded_;

    static final int SIGNATURE = 0;
    static final int ATOM = 1;
    static final int FIELD = 2;
    static final int TUPLE = 3;
    static final int SKOLEM = 4;
    static final int OTHER = 100;

    AlloyGUITreeNode() {
        super();
    }

    AlloyGUITreeNode(Object userObject) {
        this(userObject, false);
    }

    AlloyGUITreeNode(Object userObject, boolean allowsChildren) {
        this(userObject, allowsChildren, OTHER);
    }

    AlloyGUITreeNode(Object userObject, boolean allowsChildren, int type) {
        super(userObject, allowsChildren);

        nodeType = type;
        name = userObject.toString();
        alreadyExpanded_ = false;
    }

    public void setName(String newName) {
        name = newName;
    }

    public String getName() {
        return name;
    }

    public int getNodeType() {
        return nodeType;
    }
    
    public LeafExpr getLeafExpr() {
    	return leafExpr;    
    }
    
    public void setLeafExpr(LeafExpr expr) {
    	leafExpr = expr;
    }
    
    public alloy.api.Atom getAtom() {
    	return atom;
    }
    
    public void setAtom(alloy.api.Atom a) {
    	atom = a;
    }

    public boolean alreadyExpanded() {
        return alreadyExpanded_;
    }

    public void setExpanded(boolean hasExpanded) {
        alreadyExpanded_ = hasExpanded;
    }

    public String toString() {
        return name;
    }
}
